Skip to content

Add Citation Faithfulness Check notebook (RAG cookbook) - #783

Open
tonydzi wants to merge 1 commit into
cohere-ai:mainfrom
tonydzi:feat/citation-faithfulness-check
Open

Add Citation Faithfulness Check notebook (RAG cookbook)#783
tonydzi wants to merge 1 commit into
cohere-ai:mainfrom
tonydzi:feat/citation-faithfulness-check

Conversation

@tonydzi

@tonydzi tonydzi commented Jul 24, 2026

Copy link
Copy Markdown

Cohere Chat grounds answers in documents and returns citations — spans of the reply linked to the source documents they came from. This notebook adds a small, deterministic faithfulness check on top of those citations: it verifies each cited span appears verbatim in the document it is attributed to, catching the three failure modes that read as authoritative and slip past an LLM judge:

  • fabricated — a cited span that appears in no source document;
  • frankenquote — every word is real, but the exact span was never written contiguously;
  • misattributed — a real span, but the citation points at the wrong document.

The core gate is pure string work: no model, no tokens, no API key, so the first section runs in CI. A second section wires the same gate over a live co.chat (ClientV2) response and is gated behind COHERE_API_KEY.

The offline section executes end-to-end (verified with nbclient):

OK   [        found]  The car goes 400 miles per charge.
FLAG [misattributed]  Solar adds 40 miles/day.
FLAG [    not_found]  Solar alone gives 400 miles/day.
FLAG [    not_found]  Top speed is 110 mph.

Added to the RAG cookbook index in notebooks/README.md. The gate is inlined so the notebook has no extra dependency; its standalone, framework-agnostic version (plus an optional burden-of-proof LLM judge for the harder "does this span actually support the claim?" case) lives at https://github.com/Palo-Alto-AI-Research-Lab/verbatim-citation-gate .


Note

Low Risk
Documentation-only notebook and README index update; no production code or runtime behavior changes.

Overview
Adds a new RAG cookbook notebook that shows how to deterministically validate Cohere Chat citations before they reach users: each cited span must appear verbatim in the document it points to.

The notebook inlines a small normalize + gate helper (no extra package) that classifies citations as found, misattributed, or not_found, covering fabricated text, frankenquotes, and wrong-document attribution. An offline section runs on sample Cohere-shaped citations without an API key (CI-friendly); an optional section applies the same gate to live ClientV2 co.chat citations when COHERE_API_KEY is set.

notebooks/README.md gains a RAG table entry for Check Citation Faithfulness with Colab link.

Reviewed by Cursor Bugbot for commit ebb56a0. Bugbot is set up for automated code reviews on this repo. Configure here.

A deterministic, zero-token check on top of Cohere Chat citations: verify each
cited span appears verbatim in the source document it is attributed to, catching
fabricated, franken-, and misattributed citations before they reach a user. Runs
offline in CI on Cohere-shaped citations; includes a live co.chat (ClientV2)
example gated behind COHERE_API_KEY. Added to the RAG cookbook index.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tonydzi
tonydzi requested review from a team as code owners July 24, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants